// pages/search/search.js
var api = require('../../utils/api.js')
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: Object.assign({
      tabActive: 'search',
      mylist: [
        {songname:"他一定很爱你",songid:352989,artistname:"阿杜"},
        {songname:"他一定很爱你",songid:352989,artistname:"阿杜"},
        {songname:"他一定很爱你",songid:352989,artistname:"阿杜"},
        {songname:"他一定很爱你",songid:352989,artistname:"阿杜"},
        {songname:"他一定很爱你",songid:352989,artistname:"阿杜"}

      ],
      songl:[],
      search: {
        value: ''
      },
      isEnd: false,
      paged: 1
  },app.globalData.data),
  showToast(text,type="success"){
    this.setData({
      toast:{
        text,type
      }
    })
    setTimeout(() => {
      this.setData({
        toast: ""
      })
    },3000)
  },
  inputing(e) {

    this.setData({
      search: Object.assign(this.data.search, { value: e.detail.value })
    })
  },
  bindSearch(e) {
    var keyword = this.data.search.value
    if (!keyword) {
      this.showToast('请输入关键字', 'warn')
      return;
    }
    api.search(keyword, 1).then(data => {
      this.setData({
        paged: 1,
        list: data.song
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.setNavigationBarTitle({ title: "在线搜索" })
  }
})